package the.broccoli.setting.service.impl;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.wisteria.framework.web.mvc.service.AbstractSuperService;
import the.broccoli.setting.entity.Log;
import the.broccoli.setting.mapper.LogMapper;
import the.broccoli.setting.service.ILogService;

import java.util.Date;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lei.liu
 * @since 2019-11-27
 */
@Service
public class LogServiceImpl extends AbstractSuperService<LogMapper, Log> implements ILogService {

    @Transactional
    @Override
    public void loginLog(String tenantId, String operatorId, String operatorName, String ip) {
        this.businessLog(tenantId,"登录", "用户登录成功", operatorId, operatorName, ip);

    }

    @Transactional
    @Override
    public void loginFailLog(String tenantId, String operatorId, String operatorName, String ip, String failMessage) {
        this.businessLog(tenantId,"登录", "用户登录失败", operatorId, operatorName, ip);

    }

    @Transactional
    @Override
    public void logoutLog(String tenantId, String operatorId, String operatorName, String ip) {
        this.businessLog(tenantId,"登录", "用户登出", operatorId, operatorName, ip);
    }

    @Transactional
    @Override
    public void businessLog(String tenantId, String logType, String name, String operatorId, String operatorName, String ip) {
        Log log = new Log();
        log.setTenantId(tenantId);
        log.setLogType(logType);
        log.setLogName(name);
        log.setOperatorId(operatorId);
        log.setOperatorName(operatorName);
        log.setOperateTime(new Date());
        log.setIp(ip);
        this.baseMapper.insert(log);
    }
}
